package studentinformationmanagementsystem.dao.impl;

import studentinformationmanagementsystem.dao.BaseDao;
import studentinformationmanagementsystem.dao.ClassScheduleDao;
import studentinformationmanagementsystem.entity.ClassSchedule;


import java.util.List;

/**
 * @author 苗庆
 * @version 1.0
 */
public class ClassScheduleDaoImpl  extends BaseDao implements ClassScheduleDao {

    /**
     * 对课程表信息进行添加
     * @param classSchedule  课程表对象
     * @return  受影响的记录行数
     */
    @Override
    public int insert(ClassSchedule classSchedule) {
        String sql="INSERT INTO `t_classSchedule`(`whichDay`,`startingTime`,`endTime`,`singleAndDoubleWeek`,`timeOfDuration`,`teacherId`,`placeOfClass`,`courseid`,`curriculumTime`,`courseEndTime`,`IsDelete`,`attendClassObject`,`stidentmajor`)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";
        return super.update(sql,classSchedule.getWhichDay(),classSchedule.getStartingTime(),classSchedule.getEndTime(),classSchedule.getSingleAndDoubleWeek(),classSchedule.getTimeOfDuration(),classSchedule.getTeacherId(),classSchedule.getPlaceOfClass(),
                classSchedule.getCourseid(),classSchedule.getCurriculumTime(),classSchedule.getCourseEndTime(),classSchedule.getIsDelete(),classSchedule.getAttendClassObject(),classSchedule.getStidentmajor());
    }


    /**
     *  根据ID更新课程表信息
     * @param classSchedule  课程表对象
     * @return 受影响的记录行数
     */
    @Override
    public int update(ClassSchedule classSchedule) {
        String sql="UPDATE `t_classSchedule` SET `whichDay`=?,`startingTime`=?,`endTime`=?,`singleAndDoubleWeek` = ? ,`timeOfDuration` = ? ,`teacherId` = ? ,`placeOfClass` = ? ,`courseid` = ? ,`curriculumTime` = ? ,`courseEndTime` = ? ,`IsDelete` = ? ,`attendClassObject` = ? ,`stidentmajor` = ? WHERE `classScheduleId` =?";
        return super.update(sql,classSchedule.getWhichDay(),classSchedule.getStartingTime(),classSchedule.getEndTime(),classSchedule.getSingleAndDoubleWeek(),classSchedule.getTimeOfDuration(),classSchedule.getTeacherId(),classSchedule.getPlaceOfClass(),
                classSchedule.getCourseid(),classSchedule.getCurriculumTime(),classSchedule.getCourseEndTime(),classSchedule.getIsDelete(),classSchedule.getAttendClassObject(),classSchedule.getStidentmajor(),classSchedule.getClassScheduleId());
    }

    @Override
    public int update01(ClassSchedule classSchedule) {
        String sql="UPDATE `t_classSchedule` SET `whichDay`=?,`startingTime`=?,`endTime`=?,`singleAndDoubleWeek` = ? ,`timeOfDuration` = ? ,`placeOfClass` = ? WHERE `classScheduleId` =?";
        return super.update(sql,classSchedule.getWhichDay(),classSchedule.getStartingTime(),classSchedule.getEndTime(),classSchedule.getSingleAndDoubleWeek(),classSchedule.getTimeOfDuration(),classSchedule.getPlaceOfClass(), classSchedule.getClassScheduleId());
    }

    /**
     *  根据ID删除课程表
     * @param classSchedule 课程表ID
     * @return 受影响的记录行数
     */
    @Override
    public int delete(ClassSchedule classSchedule) {
        String sql="DELETE FROM `t_classSchedule` WHERE `classScheduleId`=? AND `IsDelete`=0";
        return super.update(sql,classSchedule.getClassScheduleId());
    }

    /**
     * 查询所有课程表信息
     * @return 所有课程表信息
     */
    @Override
    public List<ClassSchedule> queryAll() {
        String sql="SELECT * FROM `t_classSchedule` WHERE `IsDelete`=0 ";
        return super.queryForList(ClassSchedule.class,sql);
    }

    /**
     * 根据课程表ID查询课程表信息
     * @param classSchedule 课程表ID
     * @return 课程表信息
     */
    @Override
    public ClassSchedule queryById(ClassSchedule classSchedule) {
        String sql = "SELECT * FROM `t_classSchedule` WHERE `classScheduleId` = ?";
        return super.queryForOne(ClassSchedule.class, sql, classSchedule.getClassScheduleId());
    }


    /**
     * 根据课程id和教师id查询课程表信息   不用考虑是否删除
     * @param classSchedule 课程表ID
     * @return 课程表信息
     */
    @Override
    public ClassSchedule queryById01(ClassSchedule classSchedule) {
        String sql="SELECT * FROM `t_classSchedule` WHERE  `courseid` = ? AND `teacherId` = ? AND `curriculumTime` = ?";
        return super.queryForOne(ClassSchedule.class,sql,classSchedule.getCourseid(),classSchedule.getTeacherId(),classSchedule.getCurriculumTime());
    }

    /**
     * 查询总记录条数
     */
    @Override
    public Integer queryForPageTotalCount() {
        String sql = "SELECT COUNT(1) FROM `t_classSchedule`";
        Number count = (Number) queryForSingleValue(sql);
        return count.intValue();
    }


    /**
     * 分页查询DAO层方法
     * @param begin    起始记录行数
     * @param pageSize 每页展示数量
     * @return
     */
    @Override
    public List<ClassSchedule> queryForPageItems(int begin, int pageSize) {
        String sql = "SELECT * FROM `t_classSchedule` LIMIT ?, ?";
        return super.queryForList(ClassSchedule.class, sql, begin, pageSize);
    }

}
